@echo off
REM 部署验证脚本

echo ==========================================
echo 部署验证检查
echo ==========================================
echo.

set PROJECT_DIR=%~dp0..
set BACKEND_DIR=%PROJECT_DIR%\backend
set FRONTEND_DIR=%PROJECT_DIR%\frontend

echo [1/6] 检查Python环境...
python --version >nul 2>&1
if errorlevel 1 (
    echo   ❌ Python未安装
) else (
    python --version
    echo   ✅ Python已安装
)
echo.

echo [2/6] 检查Node.js环境...
node --version >nul 2>&1
if errorlevel 1 (
    echo   ❌ Node.js未安装
) else (
    node --version
    echo   ✅ Node.js已安装
)
echo.

echo [3/6] 检查虚拟环境...
cd /d %BACKEND_DIR%
if exist "venv" (
    echo   ✅ 虚拟环境存在
) else (
    echo   ❌ 虚拟环境不存在
)
echo.

echo [4/6] 检查Django安装...
cd /d %BACKEND_DIR%
call venv\Scripts\activate.bat >nul 2>&1
python manage.py --version >nul 2>&1
if errorlevel 1 (
    echo   ❌ Django未正确安装
) else (
    python manage.py --version
    echo   ✅ Django已安装
)
echo.

echo [5/6] 检查数据库连接...
python manage.py check --database default >nul 2>&1
if errorlevel 1 (
    echo   ❌ 数据库连接失败
    echo   请检查数据库配置和MySQL服务状态
) else (
    echo   ✅ 数据库连接正常
)
echo.

echo [6/6] 检查前端依赖...
cd /d %FRONTEND_DIR%
if exist "node_modules" (
    echo   ✅ 前端依赖已安装
) else (
    echo   ❌ 前端依赖未安装
    echo   运行: npm install
)
echo.

echo ==========================================
echo 服务状态检查
echo ==========================================
echo.

echo 检查后端服务 (http://localhost:8000)...
powershell -Command "try { $response = Invoke-WebRequest -Uri 'http://localhost:8000/api/' -TimeoutSec 2 -UseBasicParsing; Write-Host '  ✅ 后端服务运行正常 (HTTP' $response.StatusCode ')' } catch { Write-Host '  ❌ 后端服务未运行' }"

echo.
echo 检查前端服务 (http://localhost:8080)...
powershell -Command "try { $response = Invoke-WebRequest -Uri 'http://localhost:8080' -TimeoutSec 2 -UseBasicParsing; Write-Host '  ✅ 前端服务运行正常 (HTTP' $response.StatusCode ')' } catch { Write-Host '  ❌ 前端服务未运行' }"

echo.
echo ==========================================
echo 验证完成
echo ==========================================
echo.
echo 如果服务未运行，请执行：
echo   1. 启动后端: scripts\start_backend.bat
echo   2. 启动前端: scripts\start_frontend.bat
echo.
pause

